﻿@model PagedList<Core_Ticket>
@{
    ViewBag.ParentUrl = "/Ticket/Index";
    ViewBag.Title = "单证管理";
    
}
@section breadcrumb
{
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="/">控制台</a>
        </li>
        <li class="active">@ViewBag.Title</li>
    </ul><!-- .breadcrumb -->
}
<div class="row">
    <div class="col-xs-12">
        <div class="table-responsive">

            <h4 class="pink">
                <i class="ace-icon fa fa-hand-o-right icon-animated-hand-pointer blue"></i>
                <a href="###" role="button" class="green" data-toggle="modal">单证管理</a>
            </h4>
            <div class="hr hr-18 dotted hr-double"></div>
            <div class="nav-search" id="nav-search" style="top: 6px;">
                <form class="form-search">
                    <span class="">
                        <input type="text" placeholder="关键字搜索" class="nav-search-input col-xs-10 col-sm-5" style="width: 280px;" id="key" name="key" value="@Request.QueryString["key"]">
                    </span>
                    <button type="submit" class="btn btn-info btn-xs">
                        <i class="ace-icon fa fa-search bigger-110"></i>
                        搜索
                    </button>
                    @if (ViewBag.Role == 0) //超管
                    {
                        <a class="btn btn-success btn-xs" href="/ticket/edit">
                            <i class="ace-icon fa fa-plus bigger-110"></i>
                            添加单证号段
                        </a>
                    }
                </form>
            </div><!-- #nav-search -->
            <!-- PAGE CONTENT BEGINS -->
            <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th>单证名称</th>
                        <th>产品名称</th>
                        <th>剩余次数</th>
                        <th>单证号段</th>
                        <th>当前使用号</th>
                        <th>使用状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                @foreach (var item in Model)
                {

                    <tr>
                        <td>@item.T_Name</td>
                        <td>@item.T_ProductName</td>
                        <td>@item.T_RemainCount</td>
                        <td>@item.T_SNo - @item.T_ENo</td>
                        <td>@item.T_CurrentNo</td>
                        <td>@UtilPartialView.YesOrNo("是", "否", item.T_Flag == 1)</td>
                        <td>
                            @if (item.T_Flag == (int)UserStatusEnum.冻结)
                            {
                                <div class="btn-group">
                                    <a class="btn btn-xs btn-success tooltip-info" data-rel="tooltip" data-placement="top" title="使用" href="###" data-val="@item.T_Id" data-memo="@item.T_Memo" name="btnOption"  data-flag="1">
                                        使用
                                        <i class="ace-icon fa fa-check bigger-120"></i>
                                    </a>
                                </div>
                            }
                            else if (item.T_Flag == (int)UserStatusEnum.正常)
                            {
                                <div class="btn-group">
                                    <a class="btn btn-xs btn-danger tooltip-info" data-rel="tooltip" data-placement="top" title="取消使用" href="###" data-val="@item.T_Id" data-memo="@item.T_Memo"  name="btnOption"  data-flag="1">
                                        取消使用
                                        <i class="ace-icon fa fa-ban bigger-120"></i>
                                    </a>
                                </div>

                            } 
                            <div class="btn-group">
                                <a class="btn btn-xs btn-inverse tooltip-info" data-rel="tooltip" data-placement="top"  title="次数+1" href="###" data-val="@item.T_Id" data-memo="@item.T_Memo"  name="btnAddOne">
                                    +1
                                    <i class="ace-icon fa fa-outdent bigger-120"></i>
                                </a>
                            </div>

                            <div class="btn-group">
                                <a class="btn btn-xs btn-success tooltip-info" data-rel="tooltip" data-placement="top" href="/Ticket/send/?id=@{@item.T_Id}&memo=@item.T_Memo ">
                                    发放
                                    <i class="ace-icon fa fa-stack-exchange bigger-120"></i>
                                </a>
                            </div>
                            @if (ViewBag.Role == 0)
                            {
                                <div class="btn-group">
                                    <a class="btn btn-xs btn-info2 tooltip-info" data-rel="tooltip" data-placement="top" href="/ticket/edit/@item.T_Id">
                                        编辑
                                        <i class="ace-icon fa fa-edit bigger-120"></i>
                                    </a>
                                </div>

                                <div class="btn-group">
                                    <a class="btn btn-xs btn-warning tooltip-info" data-rel="tooltip" data-placement="top" href="###" data-val="@item.T_Id"   name="btnDelete" data-flag="0">
                                        删除
                                        <i class="ace-icon fa fa-ban bigger-120"></i>
                                    </a>
                                </div>
                            }
                        </td>
                    </tr>
                }
                </tbody>
            </table>
                                                                                                                                                </div> <!-- PAGE CONTENT ENDS -->
        @Html.Pager(Model, new PagerOptions { FirstPageText = "首页", PrevPageText = "上一页", NextPageText = "下一页", LastPageText = "末页", PageIndexParameterName = "id", NumericPagerItemCount = 5, ContainerTagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>", DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>", PagerItemTemplate = "<li>{0}</li>", Id = "mvcpager" })
    </div><!-- /.col -->
</div><!-- /.row -->
@section footer{
    <script src="/assets/js/bootbox.min.js"></script>
    <script>
        $(function () { 
            $('a[name="btnOption"]').on('click', function () {
                $.post('/Ticket/Option', { id: $(this).data('val'), memo: $(this).data('memo'), flag: $(this).data('flag') }, function (o) {
                    //alert(o.Msg);
                    if ('ok' == o) {
                        bootbox.alert("操作成功！", function () {
                            //window.location.reload();
                            location.reload();
                        });
                    } else {
                        bootbox.alert("操作有误！");
                    }
                });
            });
            $('a[name="btnDelete"]').on('click', function () {
                $.post('/Ticket/Remove', { id: $(this).data('val')}, function (o) {
                    //alert(o.Msg);
                    if ('ok' == o) {
                        bootbox.alert("操作成功！", function () {
                            //window.location.reload();
                            location.reload();
                        });
                    } else {
                        bootbox.alert("操作有误！");
                    }
                });
            });

            $('a[name="btnAddOne"]').on('click', function () {
                $.post('/Ticket/AddOne', { id: $(this).data('val'), memo: $(this).data('memo')}, function (o) {
                    //alert(o.Msg);
                    if ('ok' == o) {
                        bootbox.alert("操作成功！", function () {
                            //window.location.reload();
                            location.reload();
                        });
                    } else {
                        bootbox.alert("操作有误！");
                    }
                });
            });
        });
    </script>
}